#ifndef IEC101IMPL_H
#define IEC101IMPL_H

/**
 * @copyright Copyright (c) 2025 
 * CSG Digital Grid Technology (Guangdong) Co., Ltd.
 * @author zhouyan
 * @brief iec101数据解析
*/
#include "sys_inc.h"
#include "tools/m_mutex.h"

class IPhyLink;
class IEC101Private;
class IEC101Impl
{
    friend class IEC101Private;
public:
    enum LinkState {
        NOT_LINK,
        LINKED,
        LINK_LOST
    };

    enum SinglePointStatus {
        SP_OFF,
        SP_ON
    };
    enum DoublePointStatus {
        DP_ILLEGAL_00,
        DP_OFF,
        DP_ON,
        DP_ILLEGAL_11,
    };

    IEC101Impl();
    IEC101Impl(IPhyLink *phy_link, uint16_t slave_id);
    virtual ~IEC101Impl();

    bool setDevAndId(IPhyLink *phy_link, uint16_t slave_id);

    bool linkDevice(void);
    void requestData(void);

    void setGenAll(void);

    bool linked(void) const;

protected:
    virtual void OnLinkLost(void) = 0;
    virtual void OnSetSIP(uint16_t addr, SinglePointStatus sp) = 0;
    virtual void OnSetDIP(uint16_t addr, DoublePointStatus dp) = 0;
    virtual void OnSetMeasure(uint16_t addr, float v) = 0;

private:
    //  定时召唤线程
    static void *timerProc(void *argv);

protected:
    IEC101Private *private_;
};

#endif // IEC101IMPL_H
